package com.szcatic.ework.utils;

import org.apache.shiro.codec.Base64;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * 加密解密公共类
 * @author Administrator
 *
 */
public class CryptographyUtils {
	
	/**
	 * Base64加密
	 * @param str
	 * @return
	 */
	public static String encBase64(String str) {
		return Base64.encodeToString(str.getBytes());
	} 
	
	/**
	 * Base64解密
	 * @param str
	 * @return
	 */
	public static String decBase64(String str) {
		return Base64.decodeToString(str.getBytes());
	}
	
	/**
	 * Md5加密
	 * @param str
	 * @param salt
	 * @return
	 */
	public static String md5(String str ,String salt) {
		return new Md5Hash(str,salt).toString();
	}
	
	public static void main(String[] args) {
		String password = "123456";
		System.out.println(CryptographyUtils.encBase64(password));
		System.out.println(CryptographyUtils.decBase64("MTIzNDU2"));
		System.out.println(CryptographyUtils.md5(password, "szcatic"));
	}

}
